package com.guigu.buy.controller;

import com.github.pagehelper.PageInfo;
import com.guigu.buy.dto.Out_Detail;
import com.guigu.buy.pojo.OutGather;
import com.guigu.buy.service.IOutGatherService;
import com.guigu.buy.service.IProductTypeService;
import com.guigu.buy.service.IStockDetailsService;
import com.guigu.buy.utils.FileAddUtil;
import com.guigu.buy.vo.OutVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author com.guigu
 * @since 2024-05-15
 */
@CrossOrigin
@Controller
@RequestMapping("/buy/outGather")
public class OutGatherController {
    @Autowired
    private IProductTypeService productTypeService;
    @Autowired
    private IOutGatherService outGatherService;
    @Autowired
    private FileAddUtil addUtil;
    @Autowired
    private IStockDetailsService stockDetailsService;
    @RequestMapping("/addOut/{id}")
    @ResponseBody
    public String addOut(@PathVariable int id, @RequestBody Out_Detail out_detail){
        out_detail.setOutId(addUtil.getTypeNumber("400"));
        return outGatherService.add(out_detail,id);
    }
    @RequestMapping("/queryAll/{pageSize}/{pageNo}")
    @ResponseBody
    public PageInfo<Out_Detail> queryAll(@PathVariable int pageSize,
                                         @PathVariable int pageNo,
                                         @RequestBody OutVo vo){
        return outGatherService.queryAll(pageNo,pageSize,vo);
    }

    @RequestMapping("/getOne/{id}")
    @ResponseBody
    public OutGather getOne(@PathVariable int id){
        return outGatherService.getById(id);
    }

    @RequestMapping("/audit")
    @ResponseBody
    public boolean audit(@RequestBody Out_Detail out_detail){
        if(out_detail.getList()==null){
            return false;
        }
        System.out.println("通过");
        stockDetailsService.out(out_detail.getList());
        return outGatherService.updateById(out_detail);
    }
}
